/*
 * Copyright (c) dabing.io
 * All rights reserved.
 * BaseEntityListener.java
 */

package com.ueboot.weishop.entity.listener;


import com.ueboot.weishop.entity.IDEntity;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * @author ziv
 * @since 1.0
 */
public class BaseEntityListener {

	@PreUpdate
	public void preUpdate(IDEntity entity) {
		Date lastModified = new Date();
		entity.setLastModified(lastModified);
	}

	@PrePersist
	public void prePersist(IDEntity entity) {
		Date firstInsert = new Date();
		if (entity.getFirstInsert() == null) {
			entity.setFirstInsert(firstInsert);
		}
	}
}